package pkgCron

//
import (
	"fmt"
	cron1 "github.com/robfig/cron/v3"
	"log"
	"os"
)

var Cron *cron1.Cron

func init() {
	Cron = cron1.New(
		cron1.WithLogger(cron1.VerbosePrintfLogger(log.New(os.Stdout, "cron: ", log.LstdFlags))),
		//cron1.WithLogger(&CronLogger{cLog: lo}),
		//cron1.WithLogger(slog{}),
	)
}

func AddFunc(spec string, job func()) (int, error) {
	JobId, err := Cron.AddFunc(spec, job)
	return int(JobId), err
}

func Start() {
	go Cron.Start()
	defer Cron.Stop()
}

func delFunc(id int) {
	var eid cron1.EntryID
	eid = cron1.EntryID(id)
	Cron.Remove(eid)
}

func Ed(id int) {
	cc := Cron.Entry(cron1.EntryID(id))
	fmt.Println(cc)
}

type CronMap interface {
	RunCron() func()
}

func CronDel(id int) {
	delFunc(id)
	//fmt.Println("定时任务关闭", id)
}
